package com.example.demo.controller;

import com.example.demo.request.QueryRequest;
import com.example.demo.service.CozeApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/coze")
public class CozeApiController {

    @Autowired
    private CozeApiService cozeApiService;

    // API 入口，用于调用 Coze API 获取回复
    @PostMapping("/coze")
    public ResponseEntity<String> getCozeChat(@RequestBody QueryRequest request) {
        try {
            System.out.println("Received query: " + request.getQuery());
            String response = cozeApiService.cozeChat(request.getQuery());
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.status(500).body("Error: " + e.getMessage());
        }
    }
}
